﻿using System.Windows.Forms;

namespace VeryGoodSync
{
    public partial class InfoWindow : Form
    {
        private InfoWindow()
        {
            InitializeComponent();
            timer1.Interval = 1000;
            timer1.Tick += Timer1_Tick;
            Closed += InfoWindow_Closed;
        }

        private void InfoWindow_Closed(object sender, System.EventArgs e)
        {
            Closed -= InfoWindow_Closed;
            _lastWin = null;
        }

        private int _life = 3;

        private void Timer1_Tick(object sender, System.EventArgs e)
        {
            _life--;
            if (_life > 0) return;
            Close();
        }

        private static InfoWindow _lastWin;

        protected override bool ShowWithoutActivation => true;

        public static void Show(string text)
        {
            if (_lastWin == null)
            {
                _lastWin = new InfoWindow();
                _lastWin.ShowInTaskbar = false;
                _lastWin.Opacity = 0.5;
                _lastWin.Show();
                _lastWin.StartPosition = FormStartPosition.Manual;
                _lastWin.Top = 300;
                _lastWin.Left = (Screen.PrimaryScreen.Bounds.Width - _lastWin.Width) / 2;
                _lastWin.timer1.Start();
            }

            _lastWin._life = 3;
            _lastWin.label1.Text = text;
        }
    }
}
